package xm.control.bar.barContent
{
	import flash.display.DisplayObject;
	
	import xm.control.bar.base.BarBase;
	import xm.control.bar.base.ContentBase;
	
	
	/**
	 * <br> 클래스 설명 : </br>
	 * @author 김정환
	 */	
	public class TabContent extends ContentBase
	{
		
		//-----------------------------------------------------------------------------------
		// public vars
		//-----------------------------------------------------------------------------------
		
		
		
		
		//-----------------------------------------------------------------------------------
		// protected / internal vars
		//-----------------------------------------------------------------------------------
		
		
		
		
		//-----------------------------------------------------------------------------------
		// private vars
		//-----------------------------------------------------------------------------------
		
		
		//-----------------------------------------------------------------------------------
		// public functions
		//-----------------------------------------------------------------------------------
		
		/**
		 * constructor 
		 */	
		public function TabContent()
		{
			super();
		}
		
		
		/**
		 * @param s
		 */		
		override public function apply( container:BarBase ):void
		{
			super.apply( container );
			
			var tab : TabButton,
				len : int = contentList.length,
				i : int = 0,
				tabWidth : Number = 0,
				icon : DisplayObject,
				btn : DisplayObject;
				
			tabWidth = Math.ceil( container.viewWidth/len );
			
			while( i<len )
			{
				tab = contentList[ i ] as TabButton;
				if( tab != null )
				{
					btn = tab.btn;
					icon = tab.icon;
					
					btn.width = tabWidth;
					btn.x = tabWidth*i;
					btn.y = container.viewHeight-btn.height;
					
					icon.x = ( btn.width - icon.width ) / 2 + btn.x;
					icon.y = ( btn.height - icon.height ) / 2 + btn.y;
				}
				
				i++;
			}
		}
		
		//-----------------------------------------------------------------------------------
		// life cycle functions
		//-----------------------------------------------------------------------------------
		
		/**
		 * 변수, 객체 생성됨.
		 */		
		override public function createChildren():void
		{
			super.createChildren();
		}
		
		/**
		 * 생성완료시점.
		 */		
		override public function creationComplete():void
		{
			super.createChildren();
		}

		
		/**
		 * 화면에 add됨.
		 */		
		override public function add():void
		{
			var tab : TabButton,
			len : int = contentList.length,
				i : int = 0;
			
			while( i<len )
			{
				tab = contentList[ i ] as TabButton;
				container.addChild( tab.btn );
				container.addChild( tab.icon );
				i++;
			}
			
		}
		
		/**
		 * 화면에서 remove됨. 
		 */		
		override public function remove():void
		{
			var tab : TabButton,
			len : int = contentList.length,
				i : int = 0;
			
			while( i<len )
			{
				tab = contentList[ i ] as TabButton;
				if( container.contains( tab.btn ) ) container.removeChild( tab.btn );
				if( container.contains( tab.icon ) ) container.removeChild( tab.icon );
				i++;
			}
		}
		
		
		/**
		 * 메모리에서 destory됨. 
		 */		
		override public function destroy():void
		{
			super.destroy();
		}
		
		
		//-----------------------------------------------------------------------------------
		// setter / getter
		//-----------------------------------------------------------------------------------

		
		
		
		
		//-----------------------------------------------------------------------------------
		// protected functions
		//-----------------------------------------------------------------------------------
		
		
		
		//-----------------------------------------------------------------------------------
		// internal functions
		//-----------------------------------------------------------------------------------
		
		
		
		
		//-----------------------------------------------------------------------------------
		// private functions
		//-----------------------------------------------------------------------------------
		
		
		
		//-----------------------------------------------------------------------------------
		// event handler
		//-----------------------------------------------------------------------------------
		
		
		
		
		
		
		
		
		
	}
}